#include "MarvelNeutronPos.hh"

MarvelNeutronPos::MarvelNeutronPos(): MyBasePos()
{
    m_SourceDistance = 400.; // unit: mm
    m_SDWidth = 10.; // unit: mm
    m_SDHeight = 20.; // unit: mm
}

void MarvelNeutronPos::Initialize(YAML::Node yamlNode)
{
    m_SourceDistance = yamlNode["SourceDistance"].as<double>(400.);
    m_SDWidth = yamlNode["SDWidth"].as<double>(10.);
    m_SDHeight = yamlNode["SDHeight"].as<double>(20.);
}

std::pair<G4ThreeVector, G4ThreeVector> MarvelNeutronPos::GenPosAndMomDir()
{
    G4double xPoint = m_SDWidth * (G4UniformRand()-0.5);
    G4double yPoint = m_SDWidth * (G4UniformRand()-0.5);
    G4double zPoint = m_SDHeight * (G4UniformRand()-0.5);

    G4ThreeVector sourcePoint(-m_SourceDistance, 0., 0.);
    G4ThreeVector interactionPoint(xPoint, yPoint, zPoint);
    G4ThreeVector momDir = (interactionPoint - sourcePoint).unit();

    PosAndMom PosAndMomDir;
    PosAndMomDir.first = interactionPoint;
    PosAndMomDir.second = momDir;
    return PosAndMomDir;
}

REGISTPOSGEN(MarvelNeutronPos)